
import Vue from 'vue'
import Router from 'vue-router'
import Main from '../views/Main'
import HomePage from '../views/HomePage'
import UserLogin from '../views/UserLogin'
import UpLoad from '../views/UpLoad.vue'
 
Vue.use(Router);
 
const router = new Router({
  routes:[
    {
      path:'/',
      component:UserLogin
    },
    {
      path:'/Main',
      component:Main
    },
    {
      path:'/homepage',
      component:HomePage
    },
    {
      path:'/upload',
      component:UpLoad
    }
    
  ]
});

router.beforeEach((to, from, next) => {
  if (to.path === '/') return next();
  //获取token
  const tokenStr = window.sessionStorage.getItem('user_uuid')
  if (!tokenStr) return next('/')
  next()
})

export default router;